<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>notes | 川哥编程路</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/blog/image/favicon.ico">
    <link rel="stylesheet" href="/blog/css/style.css">
    <meta name="description" content="日拱一卒无有尽，功不唐捐终入海">
    
    <link rel="preload" href="/blog/assets/css/0.styles.797dfc43.css" as="style"><link rel="preload" href="/blog/assets/js/app.160d1732.js" as="script"><link rel="preload" href="/blog/assets/js/2.553eb4dc.js" as="script"><link rel="preload" href="/blog/assets/js/9.875f1e10.js" as="script"><link rel="preload" href="/blog/assets/js/3.4c6b6694.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.33b61760.js"><link rel="prefetch" href="/blog/assets/js/11.e936ed72.js"><link rel="prefetch" href="/blog/assets/js/12.06a8905b.js"><link rel="prefetch" href="/blog/assets/js/13.43d57349.js"><link rel="prefetch" href="/blog/assets/js/14.9a947fce.js"><link rel="prefetch" href="/blog/assets/js/15.00675827.js"><link rel="prefetch" href="/blog/assets/js/16.4240201a.js"><link rel="prefetch" href="/blog/assets/js/17.4e8e9f2d.js"><link rel="prefetch" href="/blog/assets/js/18.c0804ecf.js"><link rel="prefetch" href="/blog/assets/js/19.e374c696.js"><link rel="prefetch" href="/blog/assets/js/20.dc1f2462.js"><link rel="prefetch" href="/blog/assets/js/21.2550a5e8.js"><link rel="prefetch" href="/blog/assets/js/22.64bef411.js"><link rel="prefetch" href="/blog/assets/js/23.56de7058.js"><link rel="prefetch" href="/blog/assets/js/24.7de4d292.js"><link rel="prefetch" href="/blog/assets/js/25.3483b9cb.js"><link rel="prefetch" href="/blog/assets/js/26.81508f46.js"><link rel="prefetch" href="/blog/assets/js/27.f884547d.js"><link rel="prefetch" href="/blog/assets/js/28.fc8f3edd.js"><link rel="prefetch" href="/blog/assets/js/29.6df73fc7.js"><link rel="prefetch" href="/blog/assets/js/30.92ddc0da.js"><link rel="prefetch" href="/blog/assets/js/31.bc595735.js"><link rel="prefetch" href="/blog/assets/js/32.f6ddf561.js"><link rel="prefetch" href="/blog/assets/js/33.ba353a20.js"><link rel="prefetch" href="/blog/assets/js/34.23530c8e.js"><link rel="prefetch" href="/blog/assets/js/35.98587bae.js"><link rel="prefetch" href="/blog/assets/js/4.e380c258.js"><link rel="prefetch" href="/blog/assets/js/5.9b25da44.js"><link rel="prefetch" href="/blog/assets/js/6.3d19bdbc.js"><link rel="prefetch" href="/blog/assets/js/7.b8795dc7.js"><link rel="prefetch" href="/blog/assets/js/8.9332e1e8.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.797dfc43.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><!----> <span class="site-name">川哥编程路</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="php" class="dropdown-title"><span class="title">php</span> <span class="arrow down"></span></button> <button type="button" aria-label="php" class="mobile-dropdown-title"><span class="title">php</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/php/base/" class="nav-link">
  通用篇
</a></li><li class="dropdown-item"><!----> <a href="/blog/php/laravel/" class="nav-link">
  Laravel
</a></li><li class="dropdown-item"><!----> <a href="/blog/php/skill/" class="nav-link">
  技巧篇
</a></li></ul></div></div><div class="nav-item"><a href="/blog/nginx/" class="nav-link">
  nginx
</a></div><div class="nav-item"><a href="/blog/print/" class="nav-link">
  print
</a></div><div class="nav-item"><a href="/blog/mysql/" class="nav-link">
  mysql
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="web" class="dropdown-title"><span class="title">web</span> <span class="arrow down"></span></button> <button type="button" aria-label="web" class="mobile-dropdown-title"><span class="title">web</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/web/layout/" class="nav-link">
  css布局
</a></li><li class="dropdown-item"><!----> <a href="/blog/web/case/" class="nav-link">
  css实例
</a></li></ul></div></div><div class="nav-item"><a href="/blog/js/" class="nav-link">
  js
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="python" class="dropdown-title"><span class="title">python</span> <span class="arrow down"></span></button> <button type="button" aria-label="python" class="mobile-dropdown-title"><span class="title">python</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/python/base/" class="nav-link">
  python基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/python/machine/" class="nav-link">
  机器学习
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Golang" class="dropdown-title"><span class="title">Golang</span> <span class="arrow down"></span></button> <button type="button" aria-label="Golang" class="mobile-dropdown-title"><span class="title">Golang</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/go/env/" class="nav-link">
  前言和环境
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/grammar/" class="nav-link">
  语法基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/base/" class="nav-link">
  函数和数组(切片)
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/map/" class="nav-link">
  Map,指针,值传递,引用传递
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/struct/" class="nav-link">
  结构体
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/gin/" class="nav-link">
  Gin
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/concurrent/" class="nav-link">
  go并发
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/standard/" class="nav-link">
  常用标准库
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/skills/" class="nav-link">
  技巧篇
</a></li></ul></div></div><div class="nav-item"><a href="/blog/docker/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  docker
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="vue" class="dropdown-title"><span class="title">vue</span> <span class="arrow down"></span></button> <button type="button" aria-label="vue" class="mobile-dropdown-title"><span class="title">vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/vue/base/" class="nav-link">
  vue基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/assembly/" class="nav-link">
  组件化编程
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/problem/" class="nav-link">
  problem
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/uniApp/" class="nav-link">
  uniApp
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tool/" class="nav-link">
  tool
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="php" class="dropdown-title"><span class="title">php</span> <span class="arrow down"></span></button> <button type="button" aria-label="php" class="mobile-dropdown-title"><span class="title">php</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/php/base/" class="nav-link">
  通用篇
</a></li><li class="dropdown-item"><!----> <a href="/blog/php/laravel/" class="nav-link">
  Laravel
</a></li><li class="dropdown-item"><!----> <a href="/blog/php/skill/" class="nav-link">
  技巧篇
</a></li></ul></div></div><div class="nav-item"><a href="/blog/nginx/" class="nav-link">
  nginx
</a></div><div class="nav-item"><a href="/blog/print/" class="nav-link">
  print
</a></div><div class="nav-item"><a href="/blog/mysql/" class="nav-link">
  mysql
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="web" class="dropdown-title"><span class="title">web</span> <span class="arrow down"></span></button> <button type="button" aria-label="web" class="mobile-dropdown-title"><span class="title">web</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/web/layout/" class="nav-link">
  css布局
</a></li><li class="dropdown-item"><!----> <a href="/blog/web/case/" class="nav-link">
  css实例
</a></li></ul></div></div><div class="nav-item"><a href="/blog/js/" class="nav-link">
  js
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="python" class="dropdown-title"><span class="title">python</span> <span class="arrow down"></span></button> <button type="button" aria-label="python" class="mobile-dropdown-title"><span class="title">python</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/python/base/" class="nav-link">
  python基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/python/machine/" class="nav-link">
  机器学习
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Golang" class="dropdown-title"><span class="title">Golang</span> <span class="arrow down"></span></button> <button type="button" aria-label="Golang" class="mobile-dropdown-title"><span class="title">Golang</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/go/env/" class="nav-link">
  前言和环境
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/grammar/" class="nav-link">
  语法基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/base/" class="nav-link">
  函数和数组(切片)
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/map/" class="nav-link">
  Map,指针,值传递,引用传递
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/struct/" class="nav-link">
  结构体
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/gin/" class="nav-link">
  Gin
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/concurrent/" class="nav-link">
  go并发
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/standard/" class="nav-link">
  常用标准库
</a></li><li class="dropdown-item"><!----> <a href="/blog/go/skills/" class="nav-link">
  技巧篇
</a></li></ul></div></div><div class="nav-item"><a href="/blog/docker/" aria-current="page" class="nav-link router-link-exact-active router-link-active">
  docker
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="vue" class="dropdown-title"><span class="title">vue</span> <span class="arrow down"></span></button> <button type="button" aria-label="vue" class="mobile-dropdown-title"><span class="title">vue</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/vue/base/" class="nav-link">
  vue基础
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/assembly/" class="nav-link">
  组件化编程
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/problem/" class="nav-link">
  problem
</a></li><li class="dropdown-item"><!----> <a href="/blog/vue/uniApp/" class="nav-link">
  uniApp
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tool/" class="nav-link">
  tool
</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span></span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/docker/" aria-current="page" class="active sidebar-link">notes</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#docker配置镜像加速器" class="sidebar-link">docker配置镜像加速器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#centos8-2安装docker" class="sidebar-link">Centos8.2安装docker</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#docker基本命令" class="sidebar-link">docker基本命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#查看docker版本" class="sidebar-link">查看docker版本</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看版本详情" class="sidebar-link">查看版本详情</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看docker有关进程" class="sidebar-link">查看docker有关进程</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#docker启动-重启-停止命令" class="sidebar-link">docker启动|重启|停止命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#systemctl-方式" class="sidebar-link">systemctl 方式</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#service方式" class="sidebar-link">service方式</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#镜像基本命令" class="sidebar-link">镜像基本命令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#镜像搜索命令" class="sidebar-link">镜像搜索命令</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#下载镜像命令" class="sidebar-link">下载镜像命令</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#本地镜像查看" class="sidebar-link">本地镜像查看</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#本地镜像删除" class="sidebar-link">本地镜像删除</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#容器的基本操作" class="sidebar-link">容器的基本操作</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#容器创建" class="sidebar-link">容器创建</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看容器-运行中的" class="sidebar-link">查看容器(运行中的)</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看容器-包括已停止的" class="sidebar-link">查看容器(包括已停止的)</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#停止容器" class="sidebar-link">停止容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#启动容器" class="sidebar-link">启动容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#重启容器" class="sidebar-link">重启容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#删除容器" class="sidebar-link">删除容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#进入容器" class="sidebar-link">进入容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#退出容器" class="sidebar-link">退出容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#容器提交修改" class="sidebar-link">容器提交修改</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看容器日志" class="sidebar-link">查看容器日志</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#端口映射" class="sidebar-link">端口映射</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#文件挂载" class="sidebar-link">文件挂载</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#文件挂载举例实证" class="sidebar-link">文件挂载举例实证</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#文件复制" class="sidebar-link">文件复制</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#将容器的文件复制到本地" class="sidebar-link">将容器的文件复制到本地</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#将本地的文件复制到容器" class="sidebar-link">将本地的文件复制到容器</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#容器互联" class="sidebar-link">容器互联</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#细品docker技术" class="sidebar-link">细品docker技术</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#容器定时任务" class="sidebar-link">容器定时任务</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#举例-nginx容器安装" class="sidebar-link">举例: nginx容器安装</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#容器创建-2" class="sidebar-link">容器创建</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#进入容器查看nginx配置-日志-根目录" class="sidebar-link">进入容器查看nginx配置,日志,根目录</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#创建本地宿主机挂载目录" class="sidebar-link">创建本地宿主机挂载目录</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#拷贝容器中nginx所有配置文件到本地" class="sidebar-link">拷贝容器中nginx所有配置文件到本地</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#创建容器-映射端口-挂载配置文件目录和项目根目录" class="sidebar-link">创建容器,映射端口, 挂载配置文件目录和项目根目录</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#验证" class="sidebar-link">验证</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#docker-compose-容器编排" class="sidebar-link">docker-compose 容器编排</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#docker-compose-常用指令" class="sidebar-link">docker-compose 常用指令</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/docker/#启动" class="sidebar-link">启动</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#重启" class="sidebar-link">重启</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#重启某一个容器nginx" class="sidebar-link">重启某一个容器nginx</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#停止所有容器" class="sidebar-link">停止所有容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#删除所有容器" class="sidebar-link">删除所有容器</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#查看容器里面的日志" class="sidebar-link">查看容器里面的日志</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#验证容器内composer安装情况" class="sidebar-link">验证容器内composer安装情况</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#验证php容器内扩展安装情况" class="sidebar-link">验证php容器内扩展安装情况</a></li><li class="sidebar-sub-header"><a href="/blog/docker/#在宿主机中下执行项目composer-install" class="sidebar-link">在宿主机中下执行项目composer install</a></li></ul></li><li class="sidebar-sub-header"><a href="/blog/docker/#docker处理占用空间过大问题" class="sidebar-link">docker处理占用空间过大问题</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="notes"><a href="#notes" class="header-anchor">#</a> notes</h1> <h2 id="docker配置镜像加速器"><a href="#docker配置镜像加速器" class="header-anchor">#</a> docker配置镜像加速器</h2> <blockquote><p>使用加速器可以提升获取Docker官方镜像的速度</p></blockquote> <div class="language- line-numbers-mode"><pre class="language-text"><code>1. docker配置文件目录/etc/docker
2. 如果无配置文件,创建配置文件daemon.json
3. 配置文件如下:
参考: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors?accounttraceid=7ab6846acf66447dae76a6606a677deeyejb
{
  #地址为阿里云加速器地址
  &quot;registry-mirrors&quot;: [&quot;https://yg4swn7f.mirror.aliyuncs.com&quot;]
}
4. 重启配置,重启docker生效
4.1 systemctl daemon-reload
&gt;   重新加载某个服务的配置文件，如果新安装了一个服务，归属于 systemctl 管理，要是新服务的服务程序配置文件生效，需重新加载
4.2 systemctl restart docker
&gt;   重启docker服务
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="centos8-2安装docker"><a href="#centos8-2安装docker" class="header-anchor">#</a> Centos8.2安装docker</h2> <blockquote><p>ubuntu 根据命令提示安装即可, centos需要注意一些细节</p></blockquote> <p>Centos8.2安装参考: <br>
https://blog.csdn.net/weixin_41887155/article/details/107232529</p> <h2 id="docker基本命令"><a href="#docker基本命令" class="header-anchor">#</a> docker基本命令</h2> <h3 id="查看docker版本"><a href="#查看docker版本" class="header-anchor">#</a> 查看docker版本</h3> <p><code>docker -v</code></p> <h3 id="查看版本详情"><a href="#查看版本详情" class="header-anchor">#</a> 查看版本详情</h3> <p><code>docker version</code></p> <h3 id="查看docker有关进程"><a href="#查看docker有关进程" class="header-anchor">#</a> 查看docker有关进程</h3> <p><code>ps -ef | grep docker</code></p> <h2 id="docker启动-重启-停止命令"><a href="#docker启动-重启-停止命令" class="header-anchor">#</a> docker启动|重启|停止命令</h2> <h3 id="systemctl-方式"><a href="#systemctl-方式" class="header-anchor">#</a> systemctl 方式</h3> <ul><li>设置开机自启动 <code>systemctl enable docker</code></li> <li>启动 <code>systemctl start docker</code></li> <li>重启 <code>systemctl restart docker</code></li> <li>停止 <code>systemctl stop docker</code></li> <li>重载所有修改过的配置文件 <code>systemctl daemon-reload</code></li></ul> <h3 id="service方式"><a href="#service方式" class="header-anchor">#</a> service方式</h3> <ul><li>启动 <code>service docker start</code></li> <li>停止 <code>service docker stop</code></li> <li>重启 <code>service docker restart</code></li></ul> <h2 id="镜像基本命令"><a href="#镜像基本命令" class="header-anchor">#</a> 镜像基本命令</h2> <h3 id="镜像搜索命令"><a href="#镜像搜索命令" class="header-anchor">#</a> 镜像搜索命令</h3> <ul><li>搜索镜像nginx<br> <code>docker search nginx</code></li> <li>搜索官方提供的nginx镜像<br> <code>docker search --filter &quot;is-official=true&quot; nginx</code></li> <li>搜索自动化构建的nginx镜像<br> <code>docker search --filter &quot;is-automated=true&quot; nginx</code></li> <li>搜索大于等于3颗星的nginx镜像<br> <code>docker search --filter stars=3 nginx</code></li></ul> <h3 id="下载镜像命令"><a href="#下载镜像命令" class="header-anchor">#</a> 下载镜像命令</h3> <p><code>docker pull nginx</code></p> <h3 id="本地镜像查看"><a href="#本地镜像查看" class="header-anchor">#</a> 本地镜像查看</h3> <p><code>docker images</code></p> <h3 id="本地镜像删除"><a href="#本地镜像删除" class="header-anchor">#</a> 本地镜像删除</h3> <p><code>docker rmi nginx</code></p> <h2 id="容器的基本操作"><a href="#容器的基本操作" class="header-anchor">#</a> 容器的基本操作</h2> <h3 id="容器创建"><a href="#容器创建" class="header-anchor">#</a> 容器创建</h3> <p><code>docker run -itd --name=container_name image_name/镜像id</code></p> <ul><li>-i 表示以交互模式运行容器</li> <li>-d 表示后台运行容器, 并返回容器id</li> <li>-t 为容器重新分配一个伪输入终端</li> <li>–name为容器指定名称</li> <li>注意: 一个镜像可以创建多个容器,只要名字不一样就可以</li></ul> <h3 id="查看容器-运行中的"><a href="#查看容器-运行中的" class="header-anchor">#</a> 查看容器(运行中的)</h3> <p><code>docker ps</code></p> <h3 id="查看容器-包括已停止的"><a href="#查看容器-包括已停止的" class="header-anchor">#</a> 查看容器(包括已停止的)</h3> <p><code>docker ps -a</code></p> <h3 id="停止容器"><a href="#停止容器" class="header-anchor">#</a> 停止容器</h3> <p><code>docker stop container_name/container_id</code></p> <h3 id="启动容器"><a href="#启动容器" class="header-anchor">#</a> 启动容器</h3> <p><code>docker start container_name/container_id</code></p> <h3 id="重启容器"><a href="#重启容器" class="header-anchor">#</a> 重启容器</h3> <p><code>docker restart container_name/container_id</code></p> <h3 id="删除容器"><a href="#删除容器" class="header-anchor">#</a> 删除容器</h3> <blockquote><p>注意: 删除容器需要先停止容器<br> <code>docker rm container_name/container_id</code></p></blockquote> <h3 id="进入容器"><a href="#进入容器" class="header-anchor">#</a> 进入容器</h3> <p><code>docker exec -it container_name/container_id /bin/bash</code></p> <h3 id="退出容器"><a href="#退出容器" class="header-anchor">#</a> 退出容器</h3> <p><code>exit</code></p> <h3 id="容器提交修改"><a href="#容器提交修改" class="header-anchor">#</a> 容器提交修改</h3> <p><code>docker commit -a &quot;author&quot; -m &quot;message&quot; container_name/container_id new_image_name:tag_name</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>参数说明:
-a：参数可选，用于指定作者，可以写你的名字
-m：参数可选，提交信息，可以说一下你做了哪些修改
container_id：该参数为被修改的容器ID
new_image_name：此为新镜像的名字，可自定义
tag_name：此为新镜像的标签，可不写，不写时标签默认为latest
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><ul><li>修改完,停掉容器,重新启动,修改的内容还在;</li> <li>容器删除了,再次通过镜像创建容器,如果没有把容器修改内容保存到镜像中,再次创建的容器没有修改的内容;</li> <li>每个容器都很干净的,里面没有多余的命令,需要自己安装;</li></ul> <h3 id="查看容器日志"><a href="#查看容器日志" class="header-anchor">#</a> 查看容器日志</h3> <blockquote><p>当容器启动或者运行中发现问题, 需要查看运行日志时使用</p></blockquote> <p><code>docker logs 容器id/容器名称</code></p> <h2 id="端口映射"><a href="#端口映射" class="header-anchor">#</a> 端口映射</h2> <blockquote><p>解决的是客户端发送过来的请求和容器之间的交互</p></blockquote> <p><code>docker run -itd -p 宿主机端口号:容器端口号 + 镜像名字/镜像id</code></p> <h2 id="文件挂载"><a href="#文件挂载" class="header-anchor">#</a> 文件挂载</h2> <blockquote><p>解决的是宿主机和容器之间的交互;<br>
文件挂载和复制都要用绝对路径;<br>
文件挂载的意义:本地代码或者文件通过容器挂载的方式,放到容器里面,交由其来运行;</p></blockquote> <p><code>docker run -itd -v /宿主机/文件目录/文件名:/容器/目录/文件名</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>#   例子:
1. docker run -itd --name=nginx -p 80:80 -v /wwwroot/html:/usr/share/nginx/html nginx
2. docker run -itd --name=nginx -p 80:80 -v /wwwroot/:/usr/share/nginx/html/ 584256c85bdd
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="文件挂载举例实证"><a href="#文件挂载举例实证" class="header-anchor">#</a> 文件挂载举例实证</h3> <ul><li>宿主机把不存在的文件挂载到存在该文件的容器, 挂载后容器启动失败;</li> <li>宿主机把本地不存在的文件夹挂载到容器内存在的文件夹,会用一个空的文件夹覆盖容器原有的文件夹,启动启动正常,但容器内对应的目录被清空;</li> <li>宿主机存在文件挂载到容器不存在文件,挂载成功,容器内多一个挂载文件;</li> <li>宿主机存在文件夹挂载到容器不存在文件夹,挂载成功,容器内多一个文件夹;</li> <li>宿主机文件夹挂载到容器文件,启动失败;</li> <li>同名文件夹挂载,启动成功, 宿主机文件夹会覆盖容器内部的文件夹</li> <li>同名文件挂载,启动成功,宿主机会覆盖容器的文件</li> <li>宿主机文件挂载到容器文件夹,启动失败;</li></ul> <h2 id="文件复制"><a href="#文件复制" class="header-anchor">#</a> 文件复制</h2> <blockquote><p>文件挂载和复制都要用绝对路径</p></blockquote> <h3 id="将容器的文件复制到本地"><a href="#将容器的文件复制到本地" class="header-anchor">#</a> 将容器的文件复制到本地</h3> <p><code>docker cp 容器名:/容器目录/文件名 /宿主机目录/文件名</code></p> <h3 id="将本地的文件复制到容器"><a href="#将本地的文件复制到容器" class="header-anchor">#</a> 将本地的文件复制到容器</h3> <p><code>docker cp /宿主机目录/文件名 容器名:/容器目录/文件名</code></p> <h2 id="容器互联"><a href="#容器互联" class="header-anchor">#</a> 容器互联</h2> <blockquote><p>解决的是容器与容器之间的交互</p></blockquote> <p><code>docker run -itd --link 被关联的容器名字:被关联的容器的别名</code></p> <h2 id="细品docker技术"><a href="#细品docker技术" class="header-anchor">#</a> 细品docker技术</h2> <ul><li><p>docker的容器,容器启动之后,会自动运行容器里面的服务;类似nginx, nginx启动之后,我们会得到一个运行nginx软件的虚拟机; nginx是运行在容器里面的,对外提供服务的是我们的服务器, 这里的服务器可以理解为我们的***宿主机***;</p></li> <li><p>给用户提供的访问,是宿主机在提供,而不是容器再提供,那我们怎么把用户的请求,,请求到宿主机之后,自动分配给容器呢?  <code>这个就是端口映射的操作;</code></p></li> <li><p>端口映射就是把宿主机的80端口和容器的80端口两者之间关联起来;用户的所有请求到了宿主机的80端口就会自动被转发到容器的80端口;这样一来,我们所有的http请求到了宿主机之后,就会被容器里面的nginx接收到进行处理;</p></li> <li><p>docker里面的容器, 每一个容器都提供一种服务; 它不是一个容器里面提供所有的服务; 我们不会在一个服务里面, 把php, mysql, nginx都装进去, 为什么呢? <code>分开装的好处便于切换版本, 不需要动环境的东西,只需要装一个新版的容器, 切换一下容器就可以了;</code></p></li></ul> <h2 id="容器定时任务"><a href="#容器定时任务" class="header-anchor">#</a> 容器定时任务</h2> <blockquote><p>eg: 宿主机执行php容器定时任务</p></blockquote> <p><code>1 * * * * docker exec 容器ID php php文件</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker exec php容器ID php /var/www/html/api/artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="举例-nginx容器安装"><a href="#举例-nginx容器安装" class="header-anchor">#</a> 举例: nginx容器安装</h2> <h3 id="容器创建-2"><a href="#容器创建-2" class="header-anchor">#</a> 容器创建</h3> <p><code>docker run -itd --name=container_name 镜像id</code></p> <h3 id="进入容器查看nginx配置-日志-根目录"><a href="#进入容器查看nginx配置-日志-根目录" class="header-anchor">#</a> 进入容器查看nginx配置,日志,根目录</h3> <p><code>docker exec -it container_id /bin/bash</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>容器中 nginx配置文件在/etc/nginx/ 目录下面;
容器中 nginx日志在/var/log/nginx/ 目录下面;
容器中 nginx根目录在/usr/share/nginx/html/ 目录下面

特别注意: 本地挂载到容器后, 会清空或者覆盖对应的容器目录,具体规则自己体会;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="创建本地宿主机挂载目录"><a href="#创建本地宿主机挂载目录" class="header-anchor">#</a> 创建本地宿主机挂载目录</h3> <p><code>mkdir -p /data/nginx/{conf,html,logs}</code></p> <h3 id="拷贝容器中nginx所有配置文件到本地"><a href="#拷贝容器中nginx所有配置文件到本地" class="header-anchor">#</a> 拷贝容器中nginx所有配置文件到本地</h3> <p><code>docker cp 容器名:/容器目录/文件名 /宿主机目录/文件名</code></p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker cp 45744:/etc/nginx /data/nginx/conf
很多人启动容器报错,就是因为没有这一步,挂载覆盖目录问题;

上面例子表示:拷贝容器中目录nginx放到宿主机/data/nginx/conf目录下面;

上面创建的容器只是为了查看对应配置的位置,查看后可以删除了;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><h3 id="创建容器-映射端口-挂载配置文件目录和项目根目录"><a href="#创建容器-映射端口-挂载配置文件目录和项目根目录" class="header-anchor">#</a> 创建容器,映射端口, 挂载配置文件目录和项目根目录</h3> <p><code>docker run -itd --name=nginx -p 80:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx:/etc/nginx -v /data/nginx/logs:/var/log/nginx 2622</code></p> <h3 id="验证"><a href="#验证" class="header-anchor">#</a> 验证</h3> <ul><li>在本地/data/nginx/html目录下写一个index.html文件,能访问就正常了;</li> <li>如果docker ps发现容器未启动, 就要思考你的挂载和我的挂载的区别了;</li> <li>如果不能访问,查看本地防火墙是否开通80端口;</li></ul> <h2 id="docker-compose-容器编排"><a href="#docker-compose-容器编排" class="header-anchor">#</a> docker-compose 容器编排</h2> <blockquote><p>lnmp环境安装
参考:<br></p></blockquote> <ol><li>https://gitee.com/zenglingchuan/docker-compose-environment</li> <li>https://www.jianshu.com/p/d15c4e5239da</li></ol> <div class="language- line-numbers-mode"><pre class="language-text"><code># docker-compose.yml文件的版本
version: &quot;3&quot;
# 管理的服务
services: 
  php:
    hostname: php #指定容器的主机名
    restart: always #当值为 always 时，容器总是重新启动
    container_name: php #为自定义的容器指定一个名称，而不是使用默认的名称
    image: registry.cn-chengdu.aliyuncs.com/php-version/php-redis-pdo_mysql:v-1 #已经构建好的php 7.4.8
    # build: 
    #   context: ./docker/php 
    #   dockerfile: Dockerfile 
    depends_on:
      - mysql
      - redis
    ports:
      - &quot;9000:9000&quot; 
    links: 
      - mysql:mysql #指定服务容器名称:别名;避免ip方式导致的容器重启动态改变的无法连接情况
      - redis:redis 
    volumes: #容器目录  ro 容器只读; rw容器对数据卷是可读可写; 默认rw
      - ${NGINX_HTML}:/var/www/html
      - ./docker/php/php-config:/usr/local/etc   
    working_dir: /var/www/html
  nginx:
    hostname: nginx
    restart: always
    container_name: nginx
    image: nginx:1.19.2
    ports:
      - &quot;80:80&quot;
      - &quot;443:443&quot;
    depends_on:
      - nginx_api
    links:
      - &quot;nginx_api:nginx_api&quot;
    volumes:
      - ./docker/nginx/nginx-html:/usr/share/nginx/html
      - ./docker/nginx/nginx-config:/etc/nginx
      - ./docker/nginx/nginx-log:/var/log/nginx
    working_dir: /usr/share/nginx/html
  nginx_api:
    hostname: nginx
    restart: always
    container_name: nginx_api
    image: nginx:1.19.2
    ports:
      - &quot;8080:80&quot;
    depends_on:
      - php      
    links:
      - &quot;php:php&quot;
    volumes:   
      - ${NGINX_HTML}:/usr/share/nginx/html
      - ./docker/nginx-api/nginx-config:/etc/nginx
      - ./docker/nginx-api/nginx-log:/var/log/nginx
    working_dir: /usr/share/nginx/html
  mysql:
    hostname: mysql
    restart: always
    container_name: mysql
    image: mysql:8.0.21   
    ports:
      - &quot;${MYSQL_PORTS}:3306&quot;
    volumes:   
      - ./docker/mysql/database:/var/lib/mysql  
      - ./docker/mysql/mysql-config/mysql.cnf:/etc/mysql/conf.d/mysql.cnf:ro 
      - ./docker/mysql/shell:/docker-entrypoint`-initdb.d
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}     
  redis:
    hostname: redis
    restart: always
    container_name: redis
    image: redis:alpine3.12
    command: redis-server /etc/redis/redis.conf #容器启动后默认执行命令
    ports:
      - &quot;6379:6379&quot;   
    volumes:   
      - ./docker/redis/data:/data 
      - ./docker/redis/redis-config:/etc/redis 
    environment:
      - TZ=Asia/Shanghai
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br></div></div><h2 id="docker-compose-常用指令"><a href="#docker-compose-常用指令" class="header-anchor">#</a> docker-compose 常用指令</h2> <h3 id="启动"><a href="#启动" class="header-anchor">#</a> 启动</h3> <p><code>docker-compose up -d</code></p> <h3 id="重启"><a href="#重启" class="header-anchor">#</a> 重启</h3> <p><code>docker-compose restart</code></p> <h3 id="重启某一个容器nginx"><a href="#重启某一个容器nginx" class="header-anchor">#</a> 重启某一个容器nginx</h3> <p><code>docker-compose restart nginx</code></p> <h3 id="停止所有容器"><a href="#停止所有容器" class="header-anchor">#</a> 停止所有容器</h3> <p><code>docker-compose stop</code></p> <h3 id="删除所有容器"><a href="#删除所有容器" class="header-anchor">#</a> 删除所有容器</h3> <p><code>docker-compose rm</code></p> <h3 id="查看容器里面的日志"><a href="#查看容器里面的日志" class="header-anchor">#</a> 查看容器里面的日志</h3> <p><code>docker-compose logs -f nginx</code></p> <h3 id="验证容器内composer安装情况"><a href="#验证容器内composer安装情况" class="header-anchor">#</a> 验证容器内composer安装情况</h3> <p><code>docker exec 容器id composer</code></p> <h3 id="验证php容器内扩展安装情况"><a href="#验证php容器内扩展安装情况" class="header-anchor">#</a> 验证php容器内扩展安装情况</h3> <p><code>docker exec 容器id php -m</code></p> <h3 id="在宿主机中下执行项目composer-install"><a href="#在宿主机中下执行项目composer-install" class="header-anchor">#</a> 在宿主机中下执行项目composer install</h3> <p><code>docker exec 容器id composer install</code></p> <h2 id="docker处理占用空间过大问题"><a href="#docker处理占用空间过大问题" class="header-anchor">#</a> docker处理占用空间过大问题</h2> <ul><li>https://blog.csdn.net/qq_28001193/article/details/79555177</li></ul></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated:</span> <span class="time">10/27/2021, 3:16:13 PM</span></div></footer> <!----> </main></div><div class="global-ui"><!----><!----><!----></div></div>
    <script src="/blog/assets/js/app.160d1732.js" defer></script><script src="/blog/assets/js/2.553eb4dc.js" defer></script><script src="/blog/assets/js/9.875f1e10.js" defer></script><script src="/blog/assets/js/3.4c6b6694.js" defer></script>
  </body>
</html>
